#!/usr/bin/env python

from sqlalchemy import Column, Integer, String, Float, Date, ForeignKey
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import backref, mapper, relation, sessionmaker
 
Base = declarative_base()

class User(Base):
    """"""
    __tablename__ = "users"
 
    id = Column(Integer, primary_key=True)
    email_address = Column(String, nullable=False)  
    fullname = Column(String)
    password = Column(String, nullable=False)
 
    def __init__(self, email_address, fullname, password):
        """Constructor"""
        self.name = name
        self.email_address = email_address
        self.fullname = fullname
        self.password = password
 
    def __repr__(self):
        return "<User('%s','%s', '%s')>" % (self.name, self.fullname, self.password)
 

class Card(Base):
    """
    Card is the minimal unit of the knowledge
    """
    __tablename__ = "cards"
    id = Column(Integer, primary_key=True)
    hint = Column(String)
    answer = Column(String)
    user_id = Column(Integer, ForeignKey('users.id'))
 
    # creates a bidirectional relationship
    # from Address to User it's Many-to-One
    # from User to Address it's One-to-Many
    user = relation(User, backref=backref('addresses', order_by=id))
 
    #----------------------------------------------------------------------
    def __init__(self, hint, answer):
        """Constructor"""
 
    def __repr__(self):
        return "<Card('%s')>" % self.email_address
 
 
# create a connection to a sqlite database
# turn echo on to see the auto-generated SQL
engine = create_engine("sqlite:///davinci.db", echo=True)
 
# get a handle on the table object
users_table = User.__table__
# get a handle on the metadata
metadata = Base.metadata
metadata.create_all(engine)
